package com.kaifamiao.servlet;

import org.tinylog.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/session/destory")
public class SessionDestoryServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(false);
        if( session != null ) {
            Logger.trace("废弃[" + session.getId() + "]会话");
            // 废弃当前请求关联的会话对象
            session.invalidate();
        }
        response.sendRedirect( request.getContextPath() + "/" );
    }

}
